package main

import "fmt"

func main() {
	nums := []int{1, 1, 1, 2, 2, 3}
	removeDuplicates(nums)
	fmt.Printf("%v\n", nums)
}

// 快慢指针
func removeDuplicates(nums []int) int {
	if len(nums) < 2 {
		return len(nums)
	}
	fast := 2
	slow := 2

	for fast < len(nums) {
		if nums[fast] != nums[slow-2] {
			nums[slow] = nums[fast]
			slow++
		}
		fast++
	}
	return slow
}
